package com.chushouya.controller.order.clerk;

import com.chushouya.common.annotations.AuthValidate;
import com.chushouya.common.constant.ServiceType;
import com.chushouya.common.support.Contexts;
import com.chushouya.order.dto.api.clerk.*;
import com.general.framework.core.schema.PageResult;
import com.general.framework.core.schema.Response;
import com.chushouya.order.dto.admin.order.OrderLogQuery;
import com.chushouya.order.dto.admin.order.OrderLogicStatus;
import com.chushouya.order.dto.admin.orderlog.OrderLogDTO;
import com.chushouya.order.dto.admin.usercollect.OrderUserCollectDTO;
import com.chushouya.order.service.api.ClerkOrderApiService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@Api(tags = ServiceType.CLERK + "业务员订单查询接口")
@RestController
@RequestMapping(ServiceType.CLERK + "/order")
public class ClerkOrderApiController {

    @Resource
    private ClerkOrderApiService clerkOrderApiService;

    @GetMapping("/orderTodoCount")
    @ApiOperation("业务员订单代办数量")
    @AuthValidate
    public Response<ClerkOrderTodoCountDTO> orderTodoCount() {
        return Response.success(clerkOrderApiService.orderTodoCount(Contexts.getUserContext().getClerkId()));
    }

    @GetMapping("/todoOrderList")
    @ApiOperation("代办订单列表")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "todoOrderType", value = "代办类型（1等待接单 2今日预约 3等待发货）", required = true),
    })
    @AuthValidate
    public Response<List<ClerkOrderDTO>> todoOrderList(Integer todoOrderType) {
        final Long clerkId = Contexts.getUserContext().getClerkId();
        return Response.success(clerkOrderApiService.todoOrderList(clerkId, todoOrderType));
    }


    @ApiOperation("回收订单状态与数量")
    @GetMapping("/orderStatusAndCount")
    @AuthValidate
    public Response<List<OrderLogicStatus>> orderStatusAndCount() {
        return Response.success(clerkOrderApiService.orderStatusAndCount(Contexts.getUserContext().getClerkId()));
    }

    @GetMapping("/orderList")
    @ApiOperation("业务员回收订单")
    @AuthValidate
    public Response<PageResult<ClerkOrderDTO>> orderList(ClerkOrderQuery query) {
        query.setClerkId(Contexts.getUserContext().getClerkId());
        return Response.success(clerkOrderApiService.orderList(query));
    }


    @ApiOperation("收成订单状态与数量")
    @GetMapping("/completeOrderStatusAndCount")
    @AuthValidate
    public Response<List<OrderLogicStatus>> completeOrderStatusAndCount() {
        return Response.success(clerkOrderApiService.completeOrderStatusAndCount(Contexts.getUserContext().getClerkId()));
    }

    @GetMapping("/completeOrderList")
    @ApiOperation("业务员收成订单")
    @AuthValidate
    public Response<PageResult<ClerkOrderDTO>> completeOrderList(ClerkOrderQuery query) {
        query.setClerkId(Contexts.getUserContext().getClerkId());
        return Response.success(clerkOrderApiService.completeOrderList(query));
    }

    @GetMapping("/orderDetail")
    @ApiOperation("订单详情")
    @AuthValidate
    public Response<ClerkOrderDetailDTO> orderDetail(Long orderId) {
        return Response.success(clerkOrderApiService.orderDetail(Contexts.getUserContext().getClerkId(), orderId));
    }

    @GetMapping("/getOrderUserCollect")
    @ApiOperation("订单用户收款信息")
    @AuthValidate
    public Response<OrderUserCollectDTO> getOrderUserCollect(Long orderId) {
        return Response.success();
    }

    @GetMapping("/getUserCollect")
    @ApiOperation("当前订单用户历史收款信息")
    @AuthValidate
    public Response<OrderUserCollectDTO> getUserCollect(Long orderId) {
        return Response.success();
    }

    @GetMapping("/orderLogList")
    @ApiOperation("订单日志")
    @AuthValidate
    public Response<List<OrderLogDTO>> orderLogList(OrderLogQuery query) {
        return Response.success(clerkOrderApiService.orderLogList(query));
    }

    @GetMapping("/overTimeOrderList")
    @ApiOperation("业务员操作超时订单（不及时操作会影响停单的订单）")
    @AuthValidate
    public Response<List<ClerkOvertimeOrderDTO>> overTimeOrderList() {
        final Long clerkId = Contexts.getUserContext().getClerkId();
        return Response.success();
    }

    @GetMapping("/overTimeOrderCount")
    @ApiOperation("业务员操作超时数（不及时操作会影响停单的订单）")
    @AuthValidate
    public Response<Integer> overTimeOrderCount() {
        return Response.success();
    }

}
